<template>
  <div class="pagination">
    <div :class="{ hidden: hidden }">
      <a-pagination
        v-bind="$props"
        show-size-changer
        show-quick-jumper
        :show-total="(total) => `共 ${total} 条`"
        :background="background"
        v-model:current="page"
        v-model:pageSize="limit"
        :page-size-options="pageSizes"
        :total="total"
        @showSizeChange="handleSizeChange"
        @change="handleCurrentChange"
      />
    </div>
  </div>
</template>
<script lang="ts">
export default {
  name: 'Pagination',
};
</script>
<script setup lang="ts">
const props = defineProps({
  total: {
    required: true,
    type: Number,
  },
  page: {
    type: Number,
    default: 1,
  },
  limit: {
    type: Number,
    default: 20,
  },
  pageSizes: {
    type: Array,
    default() {
      return [10, 20, 30, 50];
    },
  },
  layout: {
    type: String,
    default: 'total, sizes, prev, pager, next, jumper',
  },
  background: {
    type: Boolean,
    default: true,
  },
  autoScroll: {
    type: Boolean,
    default: true,
  },
  hidden: {
    type: Boolean,
    default: false,
  },
});
const emit = defineEmits(['pagination', 'update:page', 'update:limit']);

const handleSizeChange = (page, pageSize) => {
  emit('update:limit', pageSize);
  emit('pagination', { page: page, limit: pageSize });
};

const handleCurrentChange = (current, size) => {
  emit('update:page', current);
  emit('pagination', { page: current, limit: size });
};
</script>

<style lang="less" >
.pagination {
  background-color: @component-background;
  padding: 16px 16px;
  .hidden {
    display: none;
  }
}
</style>
